package com.setup.trac.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.setup.trac.pojo.Allegati;
import com.setup.trac.pojo.condition.AllegatiFinderByIdStorico;
import com.setup.trac.pojo.condition.AllegatiFinderByIdTicket;
import com.setup.trac.service.SearchService;
import com.setup.trac.util.SQLCondition;

public class VisualizzaListaAllegatiController extends AbstractController {

	private SearchService searchService;
	private String successPage;
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String idStorico = request.getParameter("ids");
		SQLCondition sqlCondition = null;
		if(id!=null){
			sqlCondition = new AllegatiFinderByIdTicket(id);
		}else{
			sqlCondition = new AllegatiFinderByIdStorico(idStorico);
		}
		Allegati[] allegatis = getSearchService().find(new Allegati[0], sqlCondition, Allegati.class);
		ModelAndView mav = new ModelAndView(getSuccessPage());
		mav.addObject("listaAllegatiTicket", allegatis);
		return mav;
	}
	public String getSuccessPage() {
		return successPage;
	}
	public SearchService getSearchService() {
		return searchService;
	}
	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}
	public void setSuccessPage(String successPage) {
		this.successPage = successPage;
	}

}
